package com.MonkWorks.timedormitoryDB;
/**
 * used to implement ItimeProvider
 * used as a test class
 */
import java.io.IOException;
import java.util.HashMap;

import com.MonkWorks.clockDTO.User;

public class UserDBStub implements IUserDB {

	/**
	 * method fetchUser
	 * 
	 * @param username
	 * @return user Should return a user object
	 * @throws Exception
	 *             if username is not TestUser
	 */
	public User fetchUser(String username) throws Exception {
		if (username.contains("TestUser")) {
			User user = new User();
			user.setFirstName("User");
			user.setLastName("Test");
			user.setEmail("test@email.com");
			user.setPhoneNumber("1234567891");
			user.setUserType("admin");

			return user;
		} else {
			throw new IOException("unable to fetch user");
		}
	}

	/**
	 * saves a user
	 */
	public void saveUser(User user) throws Exception {
		// re-did this method to just check for null values
		// validates only required fields
		if (user.getUsername().equals(null)) {
			throw new IOException("Invalid Username");
		}
		if (user.getPassword().equals(null)) {
			throw new IOException("Invalid Password");
		}
		if (user.getemail().equals(null)) {
			throw new IOException("Invalid Email");
		}
		if (user.getUserType().equals(null)) {
			throw new IOException(
					"Something went wrong with assigning user permissions");
		}

	}

	public HashMap<String, User> fetchAll() {

		// create and populate hashmap
		HashMap<String, User> hash = new HashMap<String, User>();
		User user = new User();
		hash.put("User", user);

		user.setUsername("User");
		user.setPassword("User");
		user.setFirstName("Test");
		user.setLastName("Tester");
		user.setEmail("test@email.com");
		user.setUserType("Normal");

		return hash;

	}

	public boolean Logon(String Username, String Password) throws Exception {
		if (Username.equals("Admin") || Username.equals("User")) {
			if (Password.equals("Password") || Password.equals("1234")) {
				return true;
			} else {
				return false;
			}

		} else {
			return false;
		}

	}

}
